package com.zhanglinwei.common.utils;

import java.util.regex.Pattern;

public final class RegUtils {

    private RegUtils(){}

    /**
     * 手机号
     */
    public static boolean isPhone(String phoneNumber) {
        return ofPattern("^(1[3-9])\\d{9}$", phoneNumber);
    }

    /**
     * 邮箱
     */
    public static boolean isEmail(String email) {
        return ofPattern("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", email);
    }

    /**
     * 字母数字下划线
     */
    public static boolean isA1_(String inputStr) {
        return ofPattern("^[A-Za-z0-9_]+$", inputStr);
    }

    public static boolean ofPattern(String patternReg, String inputStr) {
        return inputStr != null && Pattern.matches(patternReg, inputStr);
    }
}
